import { http } from "@/util/request/index";

// 商品分类列表
export const categories = (params) => {
  return http.get("/api/product/categories/", {
    params,
  });
};

// 商品列表
export const goodsList = (params) => {
  return http.get("/api/products/", {
    params,
  });
};

// 新增商品
export const addGoods = (data) => {
  return http.post("/api/products/", data);
};

// 商品详情
export const goodsDetail = (id) => {
  return http.get(`/api/products/${id}/`);
};

// 编辑商品
export const editGoods = (data) => {
  return http.put(`/api/products/${data.id}/`, data);
};

// 收藏列表
export const collectList = (params) => {
  return http.get("/api/products/collects/", { params });
};

// 添加收藏
export const addCollect = (id) => {
  return http.post(`/api/products/${id}/collects/`);
};

// 取消收藏
export const delCollect = (id) => {
  return http.delete(`/api/products/${id}/collects/`);
};

// 商户选品到自己店铺
export const addStore = (data) => {
  return http.post(`/api/products/${data.product_id}/selection/`, data);
};

// 促销列表
export const activityGoodsList = () => {
  return http.get(`/api/products/promotional/`);
};

// 促销产品列表
export const promotionalGoods = (params) => {
  return http.get(`/api/products/promotional/product/`, { params });
};

// 促销产品详情
export const promotionalGoodsDetail = (id) => {
  return http.get(`/api/products/promotional/product/${id}/`);
};

// 商品类目列表
export const getSubjectList = () => {
  return http.get(`/api/merchant/subjects/`);
};

// 行业类目
export const getCategorySubjectList = () => {
  return http.get("/api/category/subject/");
};

// 商家已选择的类目
export const getMerchantSubjectList = (id) => {
  return http.get(`/api/merchtants/${id}/subject/`);
};

// 商户增加类目
export const addMerchantSubject = (data) => {
  return http.post("/api/merchants/subjects/related/", data);
};

// 商户删除类目
export const delMerchantSubject = (data) => {
  return http.delete("/api/merchants/subjects/related/", data);
};

// 商品单位
export const getUomList = () => {
  return http.get("/api/product/uom/");
};

// 运费模板列表
export const getExpressTemplateList = () => {
  return http.get("/api/express/templates/", { search: "" });
};

// 添加变体
export const addVariants = (data) => {
  return http.post(`/api/products/${data.product_id}/variant/`, data);
};

// 删除变体
export const delVariants = (product_id, variant_id) => {
  return http.delete(`/api/products/${product_id}/variant/${variant_id}/`);
};

// 变体详情
export const getVariantsDetail = (product_id, variant_id) => {
  return http.get(`/api/products/${product_id}/variant/${variant_id}/`);
};

// 修改变体
export const editVariants = (data) => {
  return http.put(
    `/api/products/${data.product_id}/variant/${data.variant_id}/`,
    data
  );
};
